import datetime

from django.db import models


class User(models.Model):
    username = models.CharField(max_length=255, unique=True)
    phone_number = models.CharField(max_length=255, unique=True)
    password = models.CharField(max_length=255)
    email = models.CharField(max_length=255)
    real_name = models.CharField(max_length=255,null=True)


class Team(models.Model):
    team_name = models.CharField(max_length=255, unique=True)
    owner = models.ForeignKey(User, on_delete=models.CASCADE)


class LinkBetweenTeamAndMember(models.Model):
    team = models.ForeignKey(Team, on_delete=models.CASCADE)
    team_member = models.ForeignKey(User, on_delete=models.CASCADE)
    membership = models.CharField(max_length=255)  # superManager / generalManager / staff


class Notice(models.Model):
    sender = models.ForeignKey(User, on_delete=models.CASCADE, related_name='m_sender')
    receiver = models.ForeignKey(User, on_delete=models.CASCADE, related_name='m_receiver')
    team = models.ForeignKey(Team, on_delete=models.CASCADE, null=True)
    send_time = models.DateTimeField()
    content = models.TextField()
    type = models.CharField(max_length=254)  # invite/apply/inviteAccept/inviteRefuse/applyAccept/applyRefuse/removeUser


class Project(models.Model):
    project_name = models.CharField(max_length=255)
    project_creator = models.ForeignKey(User, on_delete=models.CASCADE)
    team_belong_to = models.ForeignKey(Team, on_delete=models.CASCADE)
    created_time = models.DateTimeField()
    update_time = models.DateTimeField(default=None)
    description = models.CharField(max_length=255)
    recyclable = models.BooleanField(default=False)
    flag = models.CharField(max_length=254)


class Document(models.Model):
    document_name = models.CharField(max_length=255)
    document_creator = models.ForeignKey(User, on_delete=models.CASCADE)
    created_time = models.DateTimeField()
    content = models.TextField()
    project_belong_to = models.ForeignKey(Project, on_delete=models.CASCADE)
    team_belong_to = models.ForeignKey(Team, on_delete=models.CASCADE)
    update_time = models.DateTimeField(default=None)
    recyclable = models.BooleanField(default=False)
    type = models.CharField(max_length=255,null=True)


class Prototype(models.Model):
    name = models.CharField(max_length=256)
    creator = models.ForeignKey(User, on_delete=models.CASCADE)
    created_time = models.DateTimeField()
    content = models.TextField()
    project_belong_to = models.ForeignKey(Project, on_delete=models.CASCADE)
    team_belong_to = models.ForeignKey(Team, on_delete=models.CASCADE)
    update_time = models.DateTimeField(default=None)
    recyclable = models.BooleanField(default=False)
    type = models.CharField(max_length=255,null=True)


class KeptProject(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
